#include "StateScore.h"

#include "effects/Hollywood.h"
#include "MyGame.h"
#include "StringUtility.h"

StateScore::StateScore() : BaseState()
{
    singleScore = 0;
    totalScore = 0;

    timer.start(2000);
    stage = 0;

    scoreText.loadFont("fonts/unispace.ttf",24);
    scoreText.setColour(WHITE);

    GFX::setClearColour(BLACK);

    EFFECTS->fadeIn(1000,BLACK);
}

StateScore::~StateScore()
{
    //
}

void StateScore::userInput()
{
    input->update();

#ifdef PLATFORM_PC
    if(input->isQuit())
    {
        nullifyState();
        return;
    }
#endif
}

void StateScore::update()
{
    timer.update();

    if (timer.hasFinished())
    {
        switch (stage)
        {
        case 0:
        {
            totalScore += singleScore;
            singleScore = 0;
            timer.start(3000);
            ++stage;
            break;
        }
        case 1:
        {
            EFFECTS->fadeOut(1000,BLACK);
            timer.start(1000);
            ++stage;
            break;
        }
        case 2:
        {
            MyGame::GetMyGame()->globalScore = totalScore;
            setNextState(nextLevel);
            break;
        }
        } // switch
    }

    EFFECTS->update();
}

void StateScore::render()
{
    GFX::clearScreen();

    scoreText.setPosition(50,50);
    scoreText.print("Score: " + StringUtility::intToString(singleScore));
    scoreText.setPosition(50,200);
    scoreText.print("Total: " + StringUtility::intToString(totalScore));

    EFFECTS->render();
}
